package com.lagou.homewok.mr;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;


public class SortReducer extends Reducer<LongWritable, NullWritable, Text, NullWritable> {

    Text k = new Text();

    int n = 1;
    /*
    1.要全排序，所以只有1个Reducer
    2.遍历values，k值即为排序好的数值。
    3.每次遍历自增n编号
     */
    @Override
    protected void reduce(LongWritable key, Iterable<NullWritable> values, Context context) throws IOException, InterruptedException {

        String s = "";
        for (NullWritable value : values) {
            s = n + "\t" + key;
            k.set(s);
            n++;
            context.write(k, null);
        }
    }
}
